// request.js
const baseUrl = 'http://islunatic.icu:8082/mini';

function request(options) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        'Content-Type': 'application/json',
        'token': wx.getStorageSync('token'),  // 携带 token
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res);
        }
      },
      fail: (error) => {
        reject(error);
      },
    });
  });
}

export default request;
